<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符串替换标题关键词</title>
</head>
<body>
    <script>
        let xiasnn = "xiasnn是第一大美女";
        console.log(xiasnn.replace('xiasnn','xiaxia'));
        console.log(xiasnn.replace('n',search => {
            console.log(search);
        }))

        const word = ['php','css'];
        const string = '我喜欢php，但更喜欢css';
        const replaceString = word.reduce((pre,word) => {
            return pre.replace(word,`<a href="?w=${word}">${word}</a>`);
        },string);
        console.log(replaceString);
        document.body.innerHTML += replaceString;
    </script>
</body>
</html>